
package com.dw.library.view;

import java.util.ArrayList;
import java.util.List;

import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

/**
 * 
 */
public class ViewPagerIndicatorSet implements OnPageChangeListener {
  private static final String TAG = "ViewPagerIndicatorSet";
  
  private List<AbsViewPagerIndicator> indicators;
  private ViewPager mViewPager;
  
  public ViewPagerIndicatorSet(ViewPager viewPager){
    if(null == viewPager){
      throw new NullPointerException("viewPager can not be Null");
    }
    this.indicators = new ArrayList<AbsViewPagerIndicator>();
    this.mViewPager = viewPager;
    mViewPager.setOnPageChangeListener(this);
  }

  @Override
  public void onPageScrollStateChanged(int arg0) {
    for(int i = 0, len = indicators.size(); i < len; i++){
      indicators.get(i).onPageScrollStateChanged(arg0);
    }
  }

  @Override
  public void onPageScrolled(int arg0, float arg1, int arg2) {
    for(int i = 0, len = indicators.size(); i < len; i++){
      indicators.get(i).onPageScrolled(arg0, arg1, arg2);
    }
  }

  @Override
  public void onPageSelected(int arg0) {
    for(int i = 0, len = indicators.size(); i < len; i++){
      indicators.get(i).onPageSelected(arg0);
    }
  }
  
  public void addIndicator(AbsViewPagerIndicator indicator){
    indicator.setIndicatorSet(true);
    indicator.setViewPager(mViewPager);
    indicators.add(indicator);
  }
  
  public boolean removeIndicator(AbsViewPagerIndicator indicator){
    indicator.setIndicatorSet(false);
    return indicators.remove(indicator);
  }
}
